package com.sxit.tdf.server.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sxit.tdf.server.entity.bo.InsertPermissionBo;
import com.sxit.tdf.server.entity.bo.PermissionInfoBo;
import com.sxit.tdf.server.response.R;
import com.sxit.tdf.server.service.IPermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 前端控制器
 *
 * @author 橙子高
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/permission")
@Tag(name = "PermissionController", description = "权限接口")
public class PermissionController {

  @Autowired private IPermissionService permissionService;

  @Operation(summary = "获取权限列表")
  @GetMapping("/getAllPermission")
  @SaCheckLogin
  @SaCheckPermission("PERMISSION:SELECT")
  public R getAllPermission() {
    List<PermissionInfoBo> permissionList = permissionService.getPermissionList();

    return R.ok().put("data", permissionList);
  }

  @GetMapping("/getRolePermissionList")
  @Operation(summary = "获取角色的权限信息")
  @SaCheckLogin
  @SaCheckPermission("PERMISSION:SELECT")
  public R getRolePermissionList() {

    HashMap<String, List<InsertPermissionBo>> insertPermissionList =
        permissionService.getInsertPermissionList();

    return R.ok().put("data", insertPermissionList);
  }
}
